{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "portuguese-intro",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import math\n",
    "import gurobipy as gp\n",
    "from gurobipy import GRB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "announced-antarctica",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_dist_per(lng1, lat1, lng2, lat2):\n",
    "    \"\"\"\n",
    "    计算地图上任意两点的距离\n",
    "    :param lng1:\n",
    "    :param lat1:\n",
    "    :param lng2:\n",
    "    :param lat2:\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    rady1 = math.radians(lat1)\n",
    "    rady2 = math.radians(lat2)\n",
    "    a = rady1 - rady2\n",
    "    b = math.radians(lng1) - math.radians(lng2)\n",
    "    s = 2 * math.asin(\n",
    "        math.sqrt(math.sin(a / 2) ** 2 + math.cos(rady1) * math.cos(rady2) * math.sin(b / 2) ** 2)) * 6378.004\n",
    "    return s\n",
    "\n",
    "\n",
    "def get_dist(group1, group2):\n",
    "    \"\"\"\n",
    "    计算两个组的距离矩阵\n",
    "    :param group1:\n",
    "    :param group2:\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    dist_mat = np.zeros([len(group1), len(group2)])\n",
    "    for i in range(len(group1)):\n",
    "        for j in range(len(group2)):\n",
    "            # dist_mat[i,j] = ((group1[i][0]-group2[j][0])**2 + (group1[i][1]-group2[j][1])**2)**0.5\n",
    "            dist_mat[i, j] = get_dist_per(group1[i][0], group1[i][1], group2[j][0], group2[j][1])\n",
    "    return dist_mat.round(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "expired-sunrise",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = \"小规模数据.xlsx\"\n",
    "\n",
    "df0 = pd.read_excel(path, sheet_name=\"回收仓库\")\n",
    "df1 = pd.read_excel(path, sheet_name=\"分拣中心备选点\")\n",
    "df2 = pd.read_excel(path, sheet_name=\"拆解工厂\")\n",
    "df3 = pd.read_excel(path, sheet_name=\"产品数据\")\n",
    "df4 = pd.read_excel(path, sheet_name=\"其他数据\")\n",
    "\n",
    "t1_lat = df0['纬度'].dropna().tolist()\n",
    "t1_lng = df0['经度'].dropna().tolist()\n",
    "t1_s_1day = df0.iloc[:, [4, 7, 10, 13]].dropna().values.astype(\"int32\")\n",
    "t1_recall_cost = df0.iloc[:, [5, 8, 11, 14]].dropna().values\n",
    "t1_hold_cost = df0.iloc[:, [6, 9, 12, 15]].dropna().values\n",
    "\n",
    "t2_lat = df1['纬度'].dropna().tolist()\n",
    "t2_lng = df1['经度'].dropna().tolist()\n",
    "t2_cap = df1['最大容量'].dropna().tolist()\n",
    "t2_open_cost = df1.iloc[:, 5].dropna().tolist()\n",
    "t2_hold_cost = df1.iloc[:, 6:].dropna().values\n",
    "\n",
    "t3_lat = df2['纬度'].dropna().tolist()\n",
    "t3_lng = df2['经度'].dropna().tolist()\n",
    "\n",
    "volume = df3.iloc[0].values[1:]\n",
    "weight = df3.iloc[1].values[1:]\n",
    "process_cost = df3.iloc[2].values[1:]\n",
    "prices = df3.iloc[3].values[1:]\n",
    "\n",
    "vv_cost1 = df4.iloc[0, 0]\n",
    "vv_cost2 = df4.iloc[0, 1]\n",
    "vf_cost1 = df4.iloc[0, 2]\n",
    "vf_cost2 = df4.iloc[0, 3]\n",
    "period = df4.iloc[0, 4]\n",
    "\n",
    "t1_num = len(t1_lat)\n",
    "t2_num = len(t2_lat)\n",
    "t3_num = len(t3_lat)\n",
    "\n",
    "dist12 = get_dist(list(zip(t1_lng, t1_lat)), list(zip(t2_lng, t2_lat)))\n",
    "dist23 = get_dist(list(zip(t2_lng, t2_lat)), list(zip(t3_lng, t3_lat)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "taken-triumph",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "period"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "minimal-truth",
   "metadata": {},
   "source": [
    "p,c1,c2,FL1,FL2,c_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "complex-omaha",
   "metadata": {},
   "outputs": [],
   "source": [
    "I = [i for i in range(t1_num)]\n",
    "S = [s for s in range(t2_num)]\n",
    "J = [j for j in range(len(prices))]\n",
    "R = [r for r in range(t3_num)]\n",
    "T = [t for t in range(1,period+1)]\n",
    "T = {i: T[i] for i in range(len(T))}\n",
    "T_0 = [t for t in range(period)]\n",
    "K1 = [1,2,3,5]\n",
    "K1 = {i: K1[i] for i in range(len(K1))}\n",
    "K2 = [1,2,3,5]\n",
    "K2 = {i: K2[i] for i in range(len(K2))}\n",
    "q = t1_s_1day\n",
    "c_r = t1_recall_cost\n",
    "p = prices\n",
    "F = t2_open_cost\n",
    "d1 = dist12\n",
    "d2 = dist23\n",
    "c1 = vv_cost1\n",
    "c2 = vv_cost2\n",
    "FL1 = vf_cost1\n",
    "FL2 = vf_cost2\n",
    "c_p = process_cost\n",
    "h1 = t1_hold_cost\n",
    "h2 = t2_hold_cost\n",
    "cap = t2_cap\n",
    "a = volume\n",
    "m = weight\n",
    "M = np.sum(q)*period"
   ]
  },
  {
   "cell_type": "raw",
   "id": "generic-expense",
   "metadata": {},
   "source": [
    "S = [0]\n",
    "I = [0]\n",
    "R = [0]\n",
    "T={0:1,1:2,2:3,3:4,4:5}\n",
    "T_0=[0,1,2,3,4]\n",
    "K1={0:2,1:5}\n",
    "K2={0:2,1:5}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "threatened-night",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using license file C:\\Users\\CYK\\gurobi.lic\n"
     ]
    }
   ],
   "source": [
    "mip = gp.Model()\n",
    "\n",
    "x = mip.addVars(len(S), vtype=GRB.BINARY)\n",
    "y = mip.addVars(len(I), len(S), len(T)+1, vtype=GRB.BINARY)\n",
    "n1 = mip.addVars(len(I), len(K1), vtype=GRB.BINARY)\n",
    "n2 = mip.addVars(len(S), len(K2), vtype=GRB.BINARY)\n",
    "z = mip.addVars(len(S), len(R), len(T), vtype=GRB.BINARY)\n",
    "v = mip.addVars(len(S), len(T), len(J), vtype=GRB.CONTINUOUS)\n",
    "u = mip.addVars(len(I), len(S), len(T), len(K1), vtype=GRB.BINARY)\n",
    "w = mip.addVars(len(S), len(R), len(T), len(J), vtype=GRB.CONTINUOUS)\n",
    "b = mip.addVars(len(I), len(S), vtype=GRB.BINARY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "empirical-deposit",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(gp.quicksum(n1[i,k] for k in K1) == 1 for i in I)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "happy-sustainability",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(gp.quicksum(n2[s,k] for k in K2) == x[s] for s in S)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "emerging-travel",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(y[i,s,t] - x[s] <= 0 for i in I for s in S for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "mysterious-moment",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(gp.quicksum(y[i,s,t] for s in S) <= 1 for t in T for i in I)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ranking-imagination",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(b[i,s] - y[i,s,t] >= 0 for i in I for s in S for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "tamil-commerce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(gp.quicksum(b[i,s] for s in S ) == 1 for i in I)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "inner-federation",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(n1[i,k] - gp.quicksum(y[i,s,t] for s in S) <= T[t] % K1[k] for i in I for k in K1 for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "absolute-score",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(z[s,r,t] - x[s] <= 0 for s in S for r in R for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "looking-affiliation",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(gp.quicksum(z[s,r,t] for r in R) <= 1 for s in S for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "above-christmas",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(n2[s,k] - gp.quicksum(z[s,r,t] for r in R) <= T[t] % K2[k] for s in S for k in K2 for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "korean-pasta",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(K2[k]*gp.quicksum(z[s,r,t] for r in R) <= K2[k] - T[t] % K2[k] + K2[k]*(1-n2[s,k]) for s in S for t in T for k in K2)\n",
    "print()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "horizontal-collection",
   "metadata": {},
   "source": [
    "mip.addConstrs(bb[s,r] - z[s,r,t] >= 0 for s in S for r in R for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "extended-estate",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(u[i,s,t,k] - n1[i,k] - y[i,s,t] >= -1 for i in I for s in S for k in K1 for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ordered-three",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(v[s,t,j] - v[s,t-1,j] - gp.quicksum(K1[k]*q[i,j]*u[i,s,t,k] for k in K1 for i in I) + M*gp.quicksum(z[s,r,t] for r in R) >= 0 for s in S for j in J for t in T_0[1:])\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "apart-approach",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(gp.quicksum(a[j]*q[i,j]*K1[k]*u[i,s,t,k] for k in K1 for j in J for i in I) <= cap[s] for s in S for t in T)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "norwegian-suffering",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mip.addConstrs(w[s,r,t,j] - v[s,t-1,j] - gp.quicksum(K1[k]*q[i,j]*u[i,s,t,k] for k in K1 for i in I) + M*(1-z[s,r,t]) >= 0 for s in S for r in R for j in J for t in T_0[1:])\n",
    "print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "catholic-judgment",
   "metadata": {},
   "source": [
    "--------------------"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ultimate-arthritis",
   "metadata": {},
   "source": [
    "mip.addConstr(x[0] == 0)\n",
    "mip.addConstr(x[1] == 0)\n",
    "mip.addConstr(x[2] == 1)\n",
    "mip.addConstr(x[3] == 1)\n",
    "mip.addConstr(x[4] == 0)\n",
    "mip.addConstr(x[5] == 1)\n",
    "mip.addConstr(b[0,5] == 1)\n",
    "mip.addConstr(b[1,3] == 1)\n",
    "mip.addConstr(b[2,2] == 1)\n",
    "mip.addConstr(b[3,3] == 1)\n",
    "mip.addConstr(b[4,5] == 1)\n",
    "mip.addConstr(b[5,2] == 1)\n",
    "mip.addConstr(b[6,5] == 1)\n",
    "mip.addConstr(b[7,2] == 1)\n",
    "mip.addConstr(b[8,3] == 1)\n",
    "'''mip.addConstr(n1[0,1] == 1)\n",
    "mip.addConstr(n1[1,1] == 1)\n",
    "mip.addConstr(n1[2,2] == 1)\n",
    "mip.addConstr(n1[3,1] == 1)\n",
    "mip.addConstr(n1[4,1] == 1)\n",
    "mip.addConstr(n1[5,2] == 1)\n",
    "mip.addConstr(n1[6,2] == 1)\n",
    "mip.addConstr(n1[7,2] == 1)\n",
    "mip.addConstr(n1[8,1] == 1)\n",
    "mip.addConstr(bb[2,0] == 1)\n",
    "mip.addConstr(bb[3,0] == 1)\n",
    "mip.addConstr(bb[5,0] == 1)\n",
    "mip.addConstr(n2[2,2] == 1)\n",
    "mip.addConstr(n2[3,1] == 1)\n",
    "mip.addConstr(n2[5,2] == 1)'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "informal-tuesday",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Changed value of parameter timeLimit to 60.0\n",
      "   Prev: inf  Min: 0.0  Max: inf  Default: inf\n"
     ]
    }
   ],
   "source": [
    "mip.params.timeLimit = 60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "precious-agent",
   "metadata": {},
   "outputs": [],
   "source": [
    "lin1 = np.sum(p*np.sum(q,axis=0))*period\n",
    "lin2 = period*np.sum(q*c_r)\n",
    "lin3 = period*gp.quicksum(FL1/K1[k]*n1[i,k] for k in K1 for i in I)\n",
    "lin4 = 0.5*period*gp.quicksum(h1[i,j]*q[i,j]*K1[k]*n1[i,k] for i in I for j in J for k in K1)\n",
    "lin5 = period*c1*gp.quicksum(d1[i,s]*m[j]*q[i,j]*b[i,s] for i in I for s in S for j in J)\n",
    "lin6 = gp.quicksum(F[s]*x[s] for s in S)\n",
    "lin7 = period*gp.quicksum(FL2/K2[k]*n2[s,k] for s in S for k in K2)\n",
    "lin8 = gp.quicksum(h2[s,j]*v[s,t,j] for s in S for j in J for t in T)\n",
    "lin9 = period*gp.quicksum(c_p[j]*q[i,j]*b[i,s] for i in I for s in S for j in J)\n",
    "lin10 = c2*gp.quicksum(d2[s,r]*m[j]*w[s,r,t,j] for s in S for r in R for t in T for j in J)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "subsequent-ladder",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (win64)\n",
      "Thread count: 4 physical cores, 4 logical processors, using up to 4 threads\n",
      "Optimize a model with 15342 rows, 10794 columns and 129228 nonzeros\n",
      "Model fingerprint: 0x9f287f2b\n",
      "Variable types: 2160 continuous, 8634 integer (8634 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e+00, 4e+04]\n",
      "  Objective range  [3e-01, 5e+04]\n",
      "  Bounds range     [1e+00, 1e+00]\n",
      "  RHS range        [1e+00, 4e+04]\n",
      "Presolve removed 1977 rows and 138 columns\n",
      "Presolve time: 0.19s\n",
      "Presolved: 13365 rows, 10656 columns, 121977 nonzeros\n",
      "Variable types: 0 continuous, 10656 integer (8568 binary)\n",
      "\n",
      "Deterministic concurrent LP optimizer: primal and dual simplex\n",
      "Showing first log only...\n",
      "\n",
      "Concurrent spin time: 0.00s\n",
      "\n",
      "Solved with dual simplex\n",
      "\n",
      "Root relaxation: objective 5.338341e+05, 1328 iterations, 0.07 seconds\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0 533834.103    0  243          - 533834.103      -     -    0s\n",
      "H    0     0                    -32099.05210 533834.103  1763%     -    0s\n",
      "H    0     0                    120178.05420 533834.103   344%     -    0s\n",
      "H    0     0                    184982.74800 483580.458   161%     -    1s\n",
      "     0     0 483580.458    0  944 184982.748 483580.458   161%     -    1s\n",
      "     0     0 470954.105    0  949 184982.748 470954.105   155%     -    1s\n",
      "     0     0 432506.317    0 1171 184982.748 432506.317   134%     -    3s\n",
      "H    0     0                    211192.84650 432506.317   105%     -    4s\n",
      "     0     0 431458.957    0 1104 211192.847 431458.957   104%     -    4s\n",
      "H    0     0                    217359.51850 431458.957  98.5%     -    4s\n",
      "H    0     0                    238440.72700 431458.957  81.0%     -    4s\n",
      "     0     0 430976.594    0 1121 238440.727 430976.594  80.7%     -    4s\n",
      "H    0     0                    238888.67480 430976.594  80.4%     -    5s\n",
      "     0     0 430641.662    0 1150 238888.675 430641.662  80.3%     -    5s\n",
      "     0     0 430410.773    0 1117 238888.675 430410.773  80.2%     -    5s\n",
      "     0     0 430319.582    0 1137 238888.675 430319.582  80.1%     -    5s\n",
      "H    0     0                    261528.42060 429949.987  64.4%     -    5s\n",
      "     0     0 427432.636    0 1782 261528.421 427432.636  63.4%     -    9s\n",
      "     0     0 427423.671    0 1585 261528.421 427423.671  63.4%     -    9s\n",
      "     0     2 427423.671    0 1537 261528.421 427423.671  63.4%     -   10s\n",
      "    60    66 401692.244   13  558 261528.421 427423.671  63.4%  1110   15s\n",
      "H  167   141                    271048.87880 427423.671  57.7%   569   17s\n",
      "H  226   204                    285665.47880 427423.671  49.6%   460   17s\n",
      "   339   264 427423.671    5  766 285665.479 427423.671  49.6%   394   20s\n",
      "H  343   264                    286001.25750 427423.671  49.4%   398   20s\n",
      "H  355   289                    286265.73890 427423.671  49.3%   390   20s\n",
      "H  374   287                    287347.35750 427423.671  48.7%   373   20s\n",
      "   531   386 414252.821    6 1204 287347.358 427423.671  48.7%   359   25s\n",
      "H  651   466                    288192.01900 427423.671  48.3%   352   26s\n",
      "H  686   482                    288986.35750 427423.671  47.9%   347   27s\n",
      "   783   523 396156.289    8  924 288986.358 427423.671  47.9%   359   30s\n",
      "   920   611 404135.040    8 1120 288986.358 421973.858  46.0%   387   35s\n",
      "H  973   556                    306216.60900 421973.858  37.8%   377   36s\n",
      "H 1029   577                    310190.36400 421973.858  36.0%   365   37s\n",
      "  1036   578 319001.878   33 1585 310190.364 421973.858  36.0%   368   43s\n",
      "  1040   581 338802.044   43 1138 310190.364 421973.858  36.0%   367   45s\n",
      "  1045   584 348109.887   81 1780 310190.364 421973.858  36.0%   365   53s\n",
      "  1047   585 327744.452   46 1747 310190.364 421973.858  36.0%   364   55s\n",
      "  1058   597 421973.858   17 1512 310190.364 421973.858  36.0%   416   60s\n",
      "\n",
      "Cutting planes:\n",
      "  Cover: 1\n",
      "  Implied bound: 195\n",
      "  MIR: 171\n",
      "  Flow cover: 190\n",
      "  Inf proof: 1\n",
      "  Zero half: 39\n",
      "  RLT: 806\n",
      "  Relax-and-lift: 14\n",
      "\n",
      "Explored 1061 nodes (472602 simplex iterations) in 60.02 seconds\n",
      "Thread count was 4 (of 4 available processors)\n",
      "\n",
      "Solution count 10: 310190 306217 288986 ... 261528\n",
      "\n",
      "Time limit reached\n",
      "Best objective 3.101903640000e+05, best bound 4.219738577599e+05, gap 36.0371%\n"
     ]
    }
   ],
   "source": [
    "mip.update()\n",
    "mip.setObjective(lin1-(lin2+lin3+lin4+lin5+lin6+lin7+lin8+lin9+lin10),sense=GRB.MAXIMIZE)\n",
    "mip.optimize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "mental-hello",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "310190.36399999994"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mip.ObjVal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "cordless-stock",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "132000.0"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin3.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "younger-newton",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "310190.36400000006"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin1-lin2-lin3.getValue()-lin4.getValue()-lin5.getValue()-lin6.getValue()-lin7.getValue()-lin8.getValue()-lin9.getValue()-lin10.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "severe-marketing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5969400.0"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "molecular-regard",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5106300.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "eleven-liability",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "132000.0"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# t1的盘点成本\n",
    "lin3.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "instrumental-aircraft",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "42843.0"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# t1持有成本\n",
    "lin4.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "close-howard",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "34864.11"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# T1的运输成本\n",
    "lin5.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "focused-coverage",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100000.0"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# t2开放成本\n",
    "lin6.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "major-renaissance",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45000.0"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# t2的盘点成本\n",
    "lin7.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "popular-protection",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4178.300000000005"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# t2的持有成本\n",
    "lin8.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "coupled-seventh",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "126930.0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# t2的处理成本\n",
    "lin9.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "changing-turning",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "67094.226"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# t2的运输成本\n",
    "lin10.getValue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "correct-superior",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 5]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open_list = []\n",
    "for s in S:\n",
    "    if x[s].x > 0:\n",
    "        open_list.append(s)\n",
    "open_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "ancient-mexico",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: [], 1: [], 2: [], 3: [1, 2, 3, 4], 4: [], 5: [0, 5, 6, 7, 8]}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "allocation = dict()\n",
    "for i in I:\n",
    "    \n",
    "    for s in S:\n",
    "        if s not in allocation:\n",
    "            allocation[s] = list()\n",
    "        if b[i,s].x > 0.5:\n",
    "            allocation[s].append(i)\n",
    "allocation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "defined-ending",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 1, 1: 1, 2: 2, 3: 2, 4: 2, 5: 2, 6: 2, 7: 2, 8: 2}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "term_1 = dict()\n",
    "for i in I:\n",
    "    for k in K1:\n",
    "        if n1[i,k].x > 0.5:\n",
    "            term_1[i] = K1[k]\n",
    "term_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "thrown-black",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "43728.07800000001"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "period*c1*(d1[0,3]*np.sum(m*q[0])*1+\n",
    "    d1[1,3]*np.sum(m*q[1])*1+\n",
    "    d1[2,2]*np.sum(m*q[2])*1+\n",
    "    d1[3,2]*np.sum(m*q[3])*1+\n",
    "    d1[4,5]*np.sum(m*q[4])*1+\n",
    "    d1[5,5]*np.sum(m*q[5])*1+\n",
    "    d1[6,5]*np.sum(m*q[6])*1+\n",
    "    d1[7,2]*np.sum(m*q[7])*1+\n",
    "    d1[8,5]*np.sum(m*q[8])*1\n",
    "   )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "executed-description",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 5 0\n",
      "0 5 1\n",
      "0 5 2\n",
      "0 5 3\n",
      "0 5 4\n",
      "0 5 5\n",
      "0 5 6\n",
      "0 5 7\n",
      "0 5 8\n",
      "0 5 9\n",
      "0 5 10\n",
      "0 5 11\n",
      "0 5 12\n",
      "0 5 13\n",
      "0 5 14\n",
      "0 5 15\n",
      "0 5 16\n",
      "0 5 17\n",
      "0 5 18\n",
      "0 5 19\n",
      "0 5 20\n",
      "0 5 21\n",
      "0 5 22\n",
      "0 5 23\n",
      "0 5 24\n",
      "0 5 25\n",
      "0 5 26\n",
      "0 5 27\n",
      "0 5 28\n",
      "0 5 29\n",
      "1 3 0\n",
      "1 3 1\n",
      "1 3 2\n",
      "1 3 3\n",
      "1 3 4\n",
      "1 3 5\n",
      "1 3 6\n",
      "1 3 7\n",
      "1 3 8\n",
      "1 3 9\n",
      "1 3 10\n",
      "1 3 11\n",
      "1 3 12\n",
      "1 3 13\n",
      "1 3 14\n",
      "1 3 15\n",
      "1 3 16\n",
      "1 3 17\n",
      "1 3 18\n",
      "1 3 19\n",
      "1 3 20\n",
      "1 3 21\n",
      "1 3 22\n",
      "1 3 23\n",
      "1 3 24\n",
      "1 3 25\n",
      "1 3 26\n",
      "1 3 27\n",
      "1 3 28\n",
      "1 3 29\n",
      "2 3 1\n",
      "2 3 3\n",
      "2 3 5\n",
      "2 3 7\n",
      "2 3 9\n",
      "2 3 11\n",
      "2 3 13\n",
      "2 3 15\n",
      "2 3 17\n",
      "2 3 19\n",
      "2 3 21\n",
      "2 3 23\n",
      "2 3 25\n",
      "2 3 27\n",
      "2 3 29\n",
      "3 3 1\n",
      "3 3 3\n",
      "3 3 5\n",
      "3 3 7\n",
      "3 3 9\n",
      "3 3 11\n",
      "3 3 13\n",
      "3 3 15\n",
      "3 3 17\n",
      "3 3 19\n",
      "3 3 21\n",
      "3 3 23\n",
      "3 3 25\n",
      "3 3 27\n",
      "3 3 29\n",
      "4 3 1\n",
      "4 3 3\n",
      "4 3 5\n",
      "4 3 7\n",
      "4 3 9\n",
      "4 3 11\n",
      "4 3 13\n",
      "4 3 15\n",
      "4 3 17\n",
      "4 3 19\n",
      "4 3 21\n",
      "4 3 23\n",
      "4 3 25\n",
      "4 3 27\n",
      "4 3 29\n",
      "5 5 1\n",
      "5 5 3\n",
      "5 5 5\n",
      "5 5 7\n",
      "5 5 9\n",
      "5 5 11\n",
      "5 5 13\n",
      "5 5 15\n",
      "5 5 17\n",
      "5 5 19\n",
      "5 5 21\n",
      "5 5 23\n",
      "5 5 25\n",
      "5 5 27\n",
      "5 5 29\n",
      "6 5 1\n",
      "6 5 3\n",
      "6 5 5\n",
      "6 5 7\n",
      "6 5 9\n",
      "6 5 11\n",
      "6 5 13\n",
      "6 5 15\n",
      "6 5 17\n",
      "6 5 19\n",
      "6 5 21\n",
      "6 5 23\n",
      "6 5 25\n",
      "6 5 27\n",
      "6 5 29\n",
      "7 5 1\n",
      "7 5 3\n",
      "7 5 5\n",
      "7 5 7\n",
      "7 5 9\n",
      "7 5 11\n",
      "7 5 13\n",
      "7 5 15\n",
      "7 5 17\n",
      "7 5 19\n",
      "7 5 21\n",
      "7 5 23\n",
      "7 5 25\n",
      "7 5 27\n",
      "7 5 29\n",
      "8 5 1\n",
      "8 5 3\n",
      "8 5 5\n",
      "8 5 7\n",
      "8 5 9\n",
      "8 5 11\n",
      "8 5 13\n",
      "8 5 15\n",
      "8 5 17\n",
      "8 5 19\n",
      "8 5 21\n",
      "8 5 23\n",
      "8 5 25\n",
      "8 5 27\n",
      "8 5 29\n"
     ]
    }
   ],
   "source": [
    "for i in I:\n",
    "    for s in S:\n",
    "        for t in T:\n",
    "            if y[i,s,t].x > 0.9:\n",
    "                print(i,s,t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "unlike-balance",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, -0.0, -0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0], [-0.0, 0.0, 0.0, 0.0]]\n"
     ]
    }
   ],
   "source": [
    "s = 0\n",
    "stock = []\n",
    "for t in T:\n",
    "    stock.append([])\n",
    "    for j in J:\n",
    "        stock[t].append(v[s,t,j].x)\n",
    "print(stock)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "engaging-internship",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 5 0 1\n",
      "0 5 0 2\n",
      "0 5 1 1\n",
      "0 5 2 1\n",
      "0 5 3 1\n",
      "0 5 4 1\n",
      "0 5 5 1\n",
      "0 5 6 1\n",
      "0 5 7 1\n",
      "0 5 8 1\n",
      "0 5 9 1\n",
      "0 5 10 1\n",
      "0 5 11 1\n",
      "0 5 12 1\n",
      "0 5 13 1\n",
      "0 5 14 1\n",
      "0 5 15 1\n",
      "0 5 16 1\n",
      "0 5 17 1\n",
      "0 5 18 1\n",
      "0 5 19 1\n",
      "0 5 20 1\n",
      "0 5 21 1\n",
      "0 5 22 1\n",
      "0 5 23 1\n",
      "0 5 24 1\n",
      "0 5 25 1\n",
      "0 5 26 1\n",
      "0 5 27 1\n",
      "0 5 28 1\n",
      "0 5 29 1\n",
      "1 3 0 1\n",
      "1 3 1 1\n",
      "1 3 2 1\n",
      "1 3 3 1\n",
      "1 3 4 1\n",
      "1 3 5 1\n",
      "1 3 6 1\n",
      "1 3 7 1\n",
      "1 3 8 1\n",
      "1 3 9 1\n",
      "1 3 10 1\n",
      "1 3 11 1\n",
      "1 3 12 1\n",
      "1 3 13 1\n",
      "1 3 14 1\n",
      "1 3 15 1\n",
      "1 3 16 1\n",
      "1 3 17 1\n",
      "1 3 18 1\n",
      "1 3 19 1\n",
      "1 3 20 1\n",
      "1 3 21 1\n",
      "1 3 22 1\n",
      "1 3 23 1\n",
      "1 3 24 1\n",
      "1 3 25 1\n",
      "1 3 26 1\n",
      "1 3 27 1\n",
      "1 3 28 1\n",
      "1 3 29 1\n",
      "2 3 1 2\n",
      "2 3 3 2\n",
      "2 3 5 2\n",
      "2 3 7 2\n",
      "2 3 9 2\n",
      "2 3 11 2\n",
      "2 3 13 2\n",
      "2 3 15 2\n",
      "2 3 17 2\n",
      "2 3 19 2\n",
      "2 3 21 2\n",
      "2 3 23 2\n",
      "2 3 25 2\n",
      "2 3 27 2\n",
      "2 3 29 2\n",
      "3 3 1 2\n",
      "3 3 3 2\n",
      "3 3 5 2\n",
      "3 3 7 2\n",
      "3 3 9 2\n",
      "3 3 11 2\n",
      "3 3 13 2\n",
      "3 3 15 2\n",
      "3 3 17 2\n",
      "3 3 19 2\n",
      "3 3 21 2\n",
      "3 3 23 2\n",
      "3 3 25 2\n",
      "3 3 27 2\n",
      "3 3 29 2\n",
      "4 3 1 2\n",
      "4 3 3 2\n",
      "4 3 5 2\n",
      "4 3 7 2\n",
      "4 3 9 2\n",
      "4 3 11 2\n",
      "4 3 13 2\n",
      "4 3 15 2\n",
      "4 3 17 2\n",
      "4 3 19 2\n",
      "4 3 21 2\n",
      "4 3 23 2\n",
      "4 3 25 2\n",
      "4 3 27 2\n",
      "4 3 29 2\n",
      "5 5 1 2\n",
      "5 5 3 2\n",
      "5 5 5 2\n",
      "5 5 7 2\n",
      "5 5 9 2\n",
      "5 5 11 2\n",
      "5 5 13 2\n",
      "5 5 15 2\n",
      "5 5 17 2\n",
      "5 5 19 2\n",
      "5 5 21 2\n",
      "5 5 23 2\n",
      "5 5 25 2\n",
      "5 5 27 2\n",
      "5 5 29 2\n",
      "6 5 1 2\n",
      "6 5 3 2\n",
      "6 5 5 2\n",
      "6 5 7 2\n",
      "6 5 9 2\n",
      "6 5 11 2\n",
      "6 5 13 2\n",
      "6 5 15 2\n",
      "6 5 17 2\n",
      "6 5 19 2\n",
      "6 5 21 2\n",
      "6 5 23 2\n",
      "6 5 25 2\n",
      "6 5 27 2\n",
      "6 5 29 2\n",
      "7 5 1 2\n",
      "7 5 3 2\n",
      "7 5 5 2\n",
      "7 5 7 2\n",
      "7 5 9 2\n",
      "7 5 11 2\n",
      "7 5 13 2\n",
      "7 5 15 2\n",
      "7 5 17 2\n",
      "7 5 19 2\n",
      "7 5 21 2\n",
      "7 5 23 2\n",
      "7 5 25 2\n",
      "7 5 27 2\n",
      "7 5 29 2\n",
      "8 5 1 2\n",
      "8 5 3 2\n",
      "8 5 5 2\n",
      "8 5 7 2\n",
      "8 5 9 2\n",
      "8 5 11 2\n",
      "8 5 13 2\n",
      "8 5 15 2\n",
      "8 5 17 2\n",
      "8 5 19 2\n",
      "8 5 21 2\n",
      "8 5 23 2\n",
      "8 5 25 2\n",
      "8 5 27 2\n",
      "8 5 29 2\n"
     ]
    }
   ],
   "source": [
    "for i in I:\n",
    "    for s in S:\n",
    "        for t in T:\n",
    "            for k in K1:\n",
    "                if u[i,s,t,k].x > 0.5:\n",
    "                    print(i,s,t,K1[k])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "copyrighted-headline",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 0 1 1.0\n",
      "3 0 3 1.0\n",
      "3 0 5 1.0\n",
      "3 0 7 1.0\n",
      "3 0 9 1.0\n",
      "3 0 11 1.0\n",
      "3 0 13 1.0\n",
      "3 0 15 1.0\n",
      "3 0 17 1.0\n",
      "3 0 19 1.0\n",
      "3 0 21 1.0\n",
      "3 0 23 1.0\n",
      "3 0 25 1.0\n",
      "3 0 27 1.0\n",
      "3 0 29 1.0\n",
      "5 0 1 1.0\n",
      "5 0 3 1.0\n",
      "5 0 5 1.0\n",
      "5 0 7 1.0\n",
      "5 0 9 1.0\n",
      "5 0 11 1.0\n",
      "5 0 13 1.0\n",
      "5 0 15 1.0\n",
      "5 0 17 1.0\n",
      "5 0 19 1.0\n",
      "5 0 21 1.0\n",
      "5 0 23 1.0\n",
      "5 0 25 1.0\n",
      "5 0 27 1.0\n",
      "5 0 29 1.0\n"
     ]
    }
   ],
   "source": [
    "for s in S:\n",
    "    for r in R:\n",
    "        for t in T:\n",
    "            if z[s,r,t].x > 0.001:\n",
    "                print(s,r,t,z[s,r,t].x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "smaller-mounting",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{3: 2, 5: 2}"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "term_2 = dict()\n",
    "for s in S:\n",
    "    for k in K2:\n",
    "        if n2[s,k].x > 0.5:\n",
    "            term_2[s] = K2[k]\n",
    "term_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "adaptive-bacon",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 0 1 0 32.0\n",
      "3 0 1 1 1100.0\n",
      "3 0 1 2 36.0\n",
      "3 0 1 3 26.0\n",
      "3 0 3 0 40.0\n",
      "3 0 3 1 1320.0\n",
      "3 0 3 2 42.0\n",
      "3 0 3 3 30.0\n",
      "3 0 5 0 40.0\n",
      "3 0 5 1 1320.0\n",
      "3 0 5 2 42.0\n",
      "3 0 5 3 30.0\n",
      "3 0 7 0 40.0\n",
      "3 0 7 1 1320.0\n",
      "3 0 7 2 42.0\n",
      "3 0 7 3 30.0\n",
      "3 0 9 0 40.0\n",
      "3 0 9 1 1320.0\n",
      "3 0 9 2 42.0\n",
      "3 0 9 3 30.0\n",
      "3 0 11 0 40.0\n",
      "3 0 11 1 1320.0\n",
      "3 0 11 2 42.0\n",
      "3 0 11 3 30.0\n",
      "3 0 13 0 40.0\n",
      "3 0 13 1 1320.0\n",
      "3 0 13 2 42.0\n",
      "3 0 13 3 30.0\n",
      "3 0 15 0 40.0\n",
      "3 0 15 1 1320.0\n",
      "3 0 15 2 42.0\n",
      "3 0 15 3 30.0\n",
      "3 0 17 0 40.0\n",
      "3 0 17 1 1320.0\n",
      "3 0 17 2 42.0\n",
      "3 0 17 3 30.0\n",
      "3 0 19 0 40.0\n",
      "3 0 19 1 1320.0\n",
      "3 0 19 2 42.0\n",
      "3 0 19 3 30.0\n",
      "3 0 21 0 40.0\n",
      "3 0 21 1 1320.0\n",
      "3 0 21 2 42.0\n",
      "3 0 21 3 30.0\n",
      "3 0 23 0 40.0\n",
      "3 0 23 1 1320.0\n",
      "3 0 23 2 42.0\n",
      "3 0 23 3 30.0\n",
      "3 0 25 0 40.0\n",
      "3 0 25 1 1320.0\n",
      "3 0 25 2 42.0\n",
      "3 0 25 3 30.0\n",
      "3 0 27 0 40.0\n",
      "3 0 27 1 1320.0\n",
      "3 0 27 2 42.0\n",
      "3 0 27 3 30.0\n",
      "3 0 29 0 40.0\n",
      "3 0 29 1 1320.0\n",
      "3 0 29 2 42.0\n",
      "3 0 29 3 30.0\n",
      "5 0 1 0 47.0\n",
      "5 0 1 1 1076.0\n",
      "5 0 1 2 37.0\n",
      "5 0 1 3 22.0\n",
      "5 0 3 0 56.0\n",
      "5 0 3 1 1276.0\n",
      "5 0 3 2 44.0\n",
      "5 0 3 3 26.0\n",
      "5 0 5 0 56.0\n",
      "5 0 5 1 1276.0\n",
      "5 0 5 2 44.0\n",
      "5 0 5 3 26.0\n",
      "5 0 7 0 56.0\n",
      "5 0 7 1 1276.0\n",
      "5 0 7 2 44.0\n",
      "5 0 7 3 26.0\n",
      "5 0 9 0 56.0\n",
      "5 0 9 1 1276.0\n",
      "5 0 9 2 44.0\n",
      "5 0 9 3 26.0\n",
      "5 0 11 0 56.0\n",
      "5 0 11 1 1276.0\n",
      "5 0 11 2 44.0\n",
      "5 0 11 3 26.0\n",
      "5 0 13 0 56.0\n",
      "5 0 13 1 1276.0\n",
      "5 0 13 2 44.0\n",
      "5 0 13 3 26.0\n",
      "5 0 15 0 56.0\n",
      "5 0 15 1 1276.0\n",
      "5 0 15 2 44.0\n",
      "5 0 15 3 26.0\n",
      "5 0 17 0 56.0\n",
      "5 0 17 1 1276.0\n",
      "5 0 17 2 44.0\n",
      "5 0 17 3 26.0\n",
      "5 0 19 0 56.0\n",
      "5 0 19 1 1276.0\n",
      "5 0 19 2 44.0\n",
      "5 0 19 3 26.0\n",
      "5 0 21 0 56.0\n",
      "5 0 21 1 1276.0\n",
      "5 0 21 2 44.0\n",
      "5 0 21 3 26.0\n",
      "5 0 23 0 56.0\n",
      "5 0 23 1 1276.0\n",
      "5 0 23 2 44.0\n",
      "5 0 23 3 26.0\n",
      "5 0 25 0 56.0\n",
      "5 0 25 1 1276.0\n",
      "5 0 25 2 44.0\n",
      "5 0 25 3 26.0\n",
      "5 0 27 0 56.0\n",
      "5 0 27 1 1276.0\n",
      "5 0 27 2 44.0\n",
      "5 0 27 3 26.0\n",
      "5 0 29 0 56.0\n",
      "5 0 29 1 1276.0\n",
      "5 0 29 2 44.0\n",
      "5 0 29 3 26.0\n"
     ]
    }
   ],
   "source": [
    "for s in S:\n",
    "    for r in R:\n",
    "        for t in T:\n",
    "            for j in J:\n",
    "                if z[s,r,t].x > 0.5:\n",
    "                    print(s,r,t,j,w[s,r,t,j].x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "polyphonic-identity",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 5\n",
      "1 3\n",
      "2 3\n",
      "3 3\n",
      "4 3\n",
      "5 5\n",
      "6 5\n",
      "7 5\n",
      "8 5\n"
     ]
    }
   ],
   "source": [
    "for i in I:\n",
    "    for s in S:\n",
    "        if b[i,s].x >0.5:\n",
    "            print(i,s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "yellow-liquid",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
